//
//  ZXLAVManager.m
//  EPA
//
//  Created by 朱兴隆 on 16/4/21.
//  Copyright © 2016年 朱兴隆. All rights reserved.
//

#import "ZXLAVManager.h"

@interface ZXLAVManager ()
@property (nonatomic, strong) AVPlayer *player;

@end

@implementation ZXLAVManager

+ (instancetype)shareManager {
    static ZXLAVManager *manager = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        if (manager == nil) {
            manager = [ZXLAVManager new];
            manager.player = [[AVPlayer alloc] init];
            
        }
    });
    
    return manager;
}

- (void)play {
    AVPlayerItem *item = self.itemArray[self.currentIndex];
    [self.player replaceCurrentItemWithPlayerItem:item];
    [self.player play];
    
}
- (void)pause {
    [self.player pause];
    
}
- (void)previous {
    self.currentIndex --;
    if (self.currentIndex < 0) {
        self.currentIndex = self.itemArray.count - 1;
    }
    [self play];
}
- (void)next {
    self.currentIndex ++;
    if (self.currentIndex >= self.itemArray.count) {
        self.currentIndex = 0;
    }
    [self play];
}
- (void)seekToTime:(CMTime)time {
    [self.player seekToTime:time];
    
}

@end
